package phylacterium.entities;

import javax.servlet.http.HttpServletRequest;

public class UserEntity {
	public String login;
	public String password;
	public String newPassword;
	public String name;
	public Integer age;
	public String ageField;
	public Character gender;
	public Integer education;
	public Integer favouriteGenre;
	public int id;
	
	public UserEntity() {
		
	}
	
	public UserEntity(HttpServletRequest request) {
		login = request.getParameter("login");
		password = request.getParameter("password");
		newPassword = request.getParameter("newPassword");
		if (newPassword != null && newPassword.length() == 0)
			newPassword = null;
		name = request.getParameter("name");
		
		gender = request.getParameter("gender").charAt(0);
		education = Integer.parseInt(request.getParameter("education"));
		favouriteGenre = Integer.parseInt(request
				.getParameter("genre"));

		if (name.length() == 0)
			name = null;
		if (gender == 'n')
			gender = null;
		if (education == 0)
			education = null;
		if (favouriteGenre == 0)
			favouriteGenre = null;
		
		ageField = request.getParameter("age");
		
		if (ageField.length() > 0){
			try{
				age = Integer.parseInt(request.getParameter("age"));
			} catch (NumberFormatException e) {
				age = null;
			}
		}
	}
	
}
